<?php
$host="db.seng.uvic.ca"; // Host name
$username="se321g01"; // Mysql username
$password="un8bi2YM"; // Mysql password
$db_name="se321g01"; // Database name
$tbl_name="user_stats"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Personal
$time=$_POST['txtTime'];

// Get UID
$uid = $_GET['uid'];

echo $time;
echo $uid;

$result = mysql_query("SELECT time_left FROM user_stats WHERE uid='$uid'");
$row = mysql_fetch_array($result);
$time_left = $row['time_left'];

echo $time_left;

$time_total = $time_left + $time;

// Update into user_info
mysql_query("UPDATE user_stats
SET time_left='$time_total' WHERE uid='$uid'");

// Add user history
mysql_query("INSERT INTO user_history (day_stamp, points, item, uid) VALUES
(CURDATE(), '$time', 'Bought network time', '$uid')");

// Go back to profile
header("location:./profile.php?uid=" . $uid . "&tab=4");

?>
